package com.corejava.training.collections.car.pre15;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CarMutableDemo {

	public static void main(String[] args) {

		// instantiate car objects and set values for fields
		CarMutable car1 = new CarMutable();
		car1.setMake("Honda");
		car1.setModel("Accord");
		car1.setYear(2014);
		car1.setPrice(26899.89);

		CarMutable car2 = new CarMutable();
		car2.setMake("Toyota");
		car2.setModel("Hylander");
		car2.setYear(2014);
		car2.setPrice(46899.89);

		CarMutable car3 = new CarMutable();
		car3.setMake("Benz");
		car3.setModel("ML350");
		car3.setYear(2014);
		car3.setPrice(56899.89);

		// add objects to list with java 1.4 style
		List carList = new ArrayList();
		carList.add(car1);
		carList.add(car2);
		carList.add(car3);

		// read and print out from List with java 1.4 style
		Iterator it = carList.iterator();
		while (it.hasNext()) {

			CarMutable acar = (CarMutable) it.next();
			System.out.println("Car model is: " + acar.getModel());
			System.out.println("Car make is: " + acar.getMake());
			System.out.println("Car year is: " + acar.getYear());
			System.out.println("Car price is: " + acar.getPrice());
			System.out.println("---------------------------------------");

		}

	}

} // end of class
